{% macro story_card_actions(story, story_id, compact_view=False) %}
  {% set card_id = 'story-' ~ story_id %}
  {% set toggled_read = (not (story.read | default(false))) | tojson %}
  {% set news_count = story.news_items | length %}
  {% set news_count_text = '[' ~ news_count ~ ']' if news_count > 1 else '' %}
  {% set toggled_important = (not (story.important | default(false))) | tojson %}
  {% set actions %}
    <button type="button"
            class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
            x-bind:class="isOpen ? 'btn-active' : ''"
            x-on:click="isOpen = !isOpen"
            data-testid="toggle-summary"
            x-bind:aria-expanded="isOpen.toString()">
      {{ heroicon_mini("chevron-down") }}
      <span x-text="isOpen ? 'Hide details {{ news_count_text }}' : 'Show details {{ news_count_text }}'"></span>
    </button>
    <a type="button"
       class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
       href="{{ url_for('assess.story', story_id=story_id) }}"
       data-testid="open-detail-view">
      {{ heroicon_mini("document-magnifying-glass") }}
      <span>Open</span>
    </a>
    <button type="button"
            class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
            hx-put="{{ url_for('assess.story', story_id=story_id) }}"
            hx-vals='{"read": {{ toggled_read }} }'
            hx-target="#story-card-content-{{ story_id }}"
            hx-select="#story-card-content-{{ story_id }}"
            hx-push-url="false"
            hx-swap="innerHTML"
            data-testid="toggle-read">
      {% if story.read | default(false) %}
        {{ heroicon_mini("eye-slash") }}
        <span>Mark unread</span>
      {% else %}
        {{ heroicon_mini("eye") }}
        <span>Mark read</span>
      {% endif %}
    </button>
    <button type="button"
            class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
            hx-put="{{ url_for('assess.story', story_id=story_id) }}"
            hx-vals='{"important": {{ toggled_important }} }'
            hx-target="#story-card-content-{{ story_id }}"
            hx-select="#story-card-content-{{ story_id }}"
            hx-push-url="false"
            hx-swap="outerHTML"
            data-testid="toggle-important">
      {{ heroicon_mini("star") }}
      <span>
        {% if story.important | default(false) %}
          Remove important
        {% else %}
          Mark important
        {% endif %}
      </span>
    </button>
    <button type="button"
            class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
            hx-get='{{ url_for("assess.share_story") }}?story_id={{ story_id }}'
            hx-target="body"
            hx-swap="beforeend"
            data-testid="share-story">
      {{ heroicon_mini("share") }}
      <span>Share</span>
    </button>
    <a type="button"
       href="{{ url_for('assess.story_edit', story_id=story_id) }}"
       class="btn btn-outline btn-xs w-full join-item justify-start gap-2"
       data-testid="edit-story">
      {{ heroicon_mini("pencil-square") }}
      <span>Edit story</span>
    </a>
  {% endset %}

  {% if compact_view %}
    <div class="dropdown dropdown-end">
      <button type="button" class="btn btn-ghost btn-xs" tabindex="0" role="button" aria-haspopup="true" aria-label="Story actions">
        {{ heroicon_mini("ellipsis-vertical") }}
      </button>
      <div class="dropdown-content mt-2 w-48 rounded-box bg-base-100 p-2 shadow" tabindex="0">
        <div class="join join-vertical w-full">{{ actions | trim | safe }}</div>
      </div>
    </div>
  {% else %}
    <div class="join join-vertical w-40">{{ actions | trim | safe }}</div>
  {% endif %}
{% endmacro %}
